package cn.rongdao.jrkabao.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import cn.rongdao.jrkabao.R;


/**
 *
 */

public class DialogCreditCard extends Dialog {
    public DialogCreditCard(Context context) {
        super(context);
    }

    public DialogCreditCard(Context context, int themeResId) {
        super(context);
    }

    protected DialogCreditCard(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public static class Builder {

        /**
         * Helper class for creating a custom dialog
         */

        private Context activity;
        private String title;

        public Builder(Context activity) {
            this.activity = activity;
        }

        /**
         * Set the Dialog title from resource
         *
         * @param title
         * @return
         */
        public DialogCreditCard.Builder setTitle(int title) {
            this.title = (String) activity.getText(title);
            return this;
        }

        /**
         * Set the Dialog title from String
         *
         * @param title
         * @return
         */
        public DialogCreditCard.Builder setTitle(String title) {
            this.title = title;
            return this;
        }

        /**
         * Create the custom dialog
         */
        public DialogCreditCard create() {
            final DialogCreditCard dialog = new DialogCreditCard(activity, R.style.Dialog);
            dialog.setCanceledOnTouchOutside(false);
            Window window = dialog.getWindow();
            //取消标题
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            //取消状态栏
            window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            window.setBackgroundDrawable(new ColorDrawable());
            window.setContentView(R.layout.dialog_credit_card);

            ImageView ivClose = (ImageView) window.findViewById(R.id.dcc_iv_close);

            ivClose.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.cancel();
                }
            });

            return dialog;
        }
    }
}
